package com.feng.cloud.system.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feng.cloud.common.constants.SystemConstant;
import com.feng.cloud.common.request.QueryRequest;
import com.feng.cloud.common.utils.SortUtils;
import com.feng.cloud.common.utils.WebUtils;
import com.feng.cloud.system.entity.Todo;
import com.feng.cloud.system.mapper.TodoMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName TodoService
 * @Description TODO
 * @Author Better Feng
 * @Date 2020/1/5 16:48
 * @Version 1.0
 **/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@AllArgsConstructor
public class TodoService extends ServiceImpl<TodoMapper, Todo> {

    public IPage<Todo> selectListByPage(QueryRequest request) {
        LambdaQueryWrapper<Todo> queryWrapper = new LambdaQueryWrapper<>();
        String username = WebUtils.getCurrentUsername();
        queryWrapper.eq(Todo::getUsername, username);
        Page<Todo> page = new Page<>();
        SortUtils.handlePageAndSort(request,page,Todo::getCreateTime, SystemConstant.ORDER_DESC);
        return this.baseMapper.selectPage(page, queryWrapper);
    }
}
